<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>修改权限</title>
    <link href="${webroot }/static/plugins/bootstrap-3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
    <!--时间插件-->
    <link rel="stylesheet" href="${webroot }/static/css/bootstrap-datetimepicker.min.css">
    <!--重置文件-->
    <link rel="stylesheet" href="${webroot }/static/plugins/inputFile/css/style.css" />
    <link rel="stylesheet" href="${webroot }/static/plugins/inputFile/css/ssi-uploader.min.css">
    <link rel="stylesheet" href="${webroot }/static/plugins/icheck/custom.css">
    <link rel="stylesheet" href="${webroot }/static/plugins/icheck/skins/all.css">
    <link rel="stylesheet" href="${webroot }/static/css/reset.css">
    <link rel="stylesheet" href="${webroot }/static/css/merchantGrant.css">
    <jsp:include page="../common/common.jsp"/>
    <style type="text/css">
    	.help-block{
        	float: left;
        	padding-left: 160px;
        }
        .form-group{
        	width:100%!important;
        }
        .has-feedback{
        	width: 480px;
        }
    </style>
</head>
<body>
<section class="content">
    <ol class="breadcrumb">
        <li>权限管理</li>
        <li class="active">修改权限</li>
    </ol>
    <article id="defaultForm"  class="searchsForm clearfix form-horizontal">
        <form  id="editPermissionForm" method="post" class="form-horizontal">
            <div class="form-group clearfix">
                <div class="col-lg-6 col-md-6">
                </div>
                <div class="col-lg-6 col-md-6">
                    <a  id="subButton" class="btn btn-primary w-50 fr" style="margin-left: 10px; margin-right: 10px;" onclick="editPermission('editPermissionForm');" >提交</a>
                    <a href="${webroot}/admin/page/system/permissionUpdate?id=${param.id }&parentId=${param.parentId }&permissionType=${param.permissionType }" title="编辑"><input type="text" class="btn btn-primary w-50 fr btn-reset" value="重置"></a>
                    <a style="color: #fff;" href="javascript:history.go(-1);"><input  type="text" id="backButton" value="返回上一级" class="btn btn-primary w-50 fr" style="margin-left: 10px;width: 98px !important; margin-right: 10px;"></a>
                </div>
            </div>
            <div class="form-group clearfix">
                <span style="color: red;">注意：带“*”号的都是必填项！</span>
            </div>
            <div class="form-group clearfix">
                <label class="fl w-160 control-label">权限名称<font style="color: red;"> *</font></label>
                <div class="fl w-300">
                    <input type="text" name="zhName" value="" id="zhName" class="form-control" readonly/>
                </div>
                <span class="fl h-34" style="color: gray">权限名称一般是具体功能相关的名字</span>
            </div>
            <div class="form-group clearfix">
                <label class="fl w-160 control-label">权限标识<font style="color: red;"> *</font></label>
                <div class="fl w-300">
                    <input type="text" name="enName" value="" id="enName" class="form-control" readonly/>
                </div>
                <span class="fl h-34" style="color: gray">权限标识一般由：模块标识+功能标识构成</span>
            </div>
            <div class="form-group clearfix">
                <label class="fl w-160 control-label">路径<font style="color: red;"> *</font></label>
                <div class="fl w-300">
                    <input type="text" name="url" value="-"  id="url" class="form-control" />
                </div>
                <span class="fl h-34" style="color: gray">板块菜单/模块菜单可以不用填写url；页面菜单/按钮操作必须填写该选项</span>
            </div>
            <div class="form-group clearfix">
                <label class="fl w-160 control-label">所需操作权限<font style="color: red;"> *</font></label>
                <div class="fl w-300">
                    <input type="text" name="permission" value="" id="permission" class="form-control"/>
                </div>
                <span class="fl h-34" style="color: gray">操作权限示例：xxx:view(视图)，xxxAdd:action(新增),xxxUpdate:action(修改)等</span>
            </div>
            <div class="form-group clearfix">
                <label class="fl w-160 control-label">父编码<font style="color: red;"> *</font></label>
                <div class="fl w-300">
                    <input type="text" name="parentId"  id="parentId" class="form-control" value="${param.parentId }" readonly/>
                </div>
                <span class="fl h-34" style="color: gray">该项的值由上一级页面决定，赋默认值，不能修改。</span>
            </div>
            <div class="form-group clearfix">
                <label class="fl w-160 control-label">权限类型<font style="color: red;"> *</font></label>
                <div class="fl w-120 posiRE">
                    <input type="radio" checked="checked"  name="permissionType" value="${param.permissionType }"/>
                    <c:choose>
                        <c:when test="${param.permissionType eq 1}"><span>板块菜单</span></c:when>
                        <c:when test="${param.permissionType eq 2}"><span>模块菜单</span></c:when>
                        <c:when test="${param.permissionType eq 3}"><span>页面菜单</span></c:when>
                        <c:when test="${param.permissionType eq 4}"><span>按钮操作</span></c:when>
                    </c:choose>
                </div>
                <span class="fl h-34" style="color: gray">该项的值由上一级页面决定，赋默认值，不能修改</span>
            </div>
            <div class="form-group clearfix">
                <label class="fl w-160 control-label">状态<font style="color: red;"> *</font></label>
                <div class="fl w-120 posiRE">
                    <input type="radio" name="status" value="2"/>
                    <span>禁用</span>
                </div>
                <div class="fl w-120 posiRE">
                    <input type="radio"  name="status" value="1"/>
                    <span>启用</span>
                </div>
            </div>
            <div class="form-group clearfix">
                <label class="fl w-160 control-label">备注&nbsp;&nbsp;</label>
                <div class="fl w-300">
                    <input type="text" value="" name="remark" id="remark" class="form-control" />
                </div>
            </div>
            <input type="hidden" id="id" name="id" value="${param.id}">
        </form>
    </article>
</section>
</body>
<script type="text/javascript">
var permissionId = "${param.id}";
$(document).ready(function(){
	// icheck
	$('input').iCheck({
	    checkboxClass: 'icheckbox_square-green',
	    radioClass: 'iradio_square-green',
	    increaseArea: '20%' // optional
	});
	if(permissionId != null && permissionId != ""){
		initFormData(permissionId);
	}
})
//初始化form数据
function initFormData(roleId){
	$.ajax({
        type:'post',
        url:webroot+'/admin/system/queryPermissionById',
        data:{"permissionId":permissionId},
        dataType:'json',
        success:function(data){
        	if(checkResponseData(data,"0")){
        		var sysPermission = data.sysPermission;
        		$("#id").val(sysPermission.id);
        		$("#remark").val(sysPermission.remark);
        		$("#url").val(sysPermission.url);
        		$("#permission").val(sysPermission.permission);
        		$("#enName").val(sysPermission.enName);
        		$("#zhName").val(sysPermission.zhName);
        		$("input:radio[name='status'][value='"+sysPermission.status+"']").iCheck('check'); 
        	}
        },
        error:function(){
            alert("请求角色信息异常，请查找原因！");
        }
    });
}

function editPermission(formId){
	var permissionType = "${param.permissionType }";
	if(permissionType == "3" || permissionType == "4"){
		var url = $("#url").val();
		if(url == null || url.trim() == ""){
			$.alert({title:"错误", content:"编辑页面菜单权限或按钮操作权限时，路径不能为空！"});
			return;
		}
	}
	var bootstrapValidatorData = $("#" + formId).data('bootstrapValidator');
    if (bootstrapValidatorData) {
    	//修复记忆的组件不验证
    	bootstrapValidatorData.validate();
        if (!bootstrapValidatorData.isValid()) {
            return false;
        }
    }
	$.confirm({
		title: false,
		type:'green',
		content: '确认修改权限吗？',
		autoClose: 'cancle|3000',
		backgroundDismiss: true,
		buttons: {
			ok: {
				btnClass: 'waves-effect waves-button',
				text: '确定',
				action: function(){
					$.ajax({
				        type: "POST",
				        dataType: "json",
				        url: webroot+"/admin/system/updatePermission",
				        data: $("#" + formId).serialize(),
				        success:function(data){
				        	checkResponseData(data,"1",webroot + "/admin/page/system/permissionList?parentId=${param.parentId}&permissionType=${param.permissionType }");
				        },
				        error:function(){
				            $.alert({title:"错误", content:"请求修改权限接口错误，请查找原因！"});
				        }
				    });
				}
			},
			cancle: {
	            text: '取消',
	            btnClass: 'btn-primary',
	            action: function(){
	                // button action.
	            }
	        }
		}
	});
}
</script>
</html>

